package com.espoir.service.impl;

import com.espoir.mapper.IShpMapper;
import com.espoir.pojo.Coordinate;
import com.espoir.pojo.Shp;
import com.espoir.service.IShpService;
import com.espoir.shp.read01.CommonShapeModel;
import com.espoir.shp.read01.CountyShapeModel;
import com.espoir.shp.read01.ShapeModel;
import com.espoir.shp.read01.TownshipShapeModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShpServiceImpl implements IShpService {

    @Autowired
    private IShpMapper shpMapper;

    @Override
    public List<Shp> findAll() {
        return shpMapper.findAll();
    }

    @Override
    public Shp findById(int id) {
        return shpMapper.findById(id);
    }

    @Override
    public int save(Shp shp) {

        return shpMapper.save(shp);
    }

    @Override
    public Shp findById2(int id) {
        return shpMapper.findById2(id);
    }

    @Override
    public int save2(Shp shp) {
        return shpMapper.save2(shp);
    }

    @Override
    public int save3(ShapeModel shapeModel) {

        return shpMapper.save3(shapeModel);
    }

    @Override
    public int saveCountyShape(CountyShapeModel shapeModel) {
        return shpMapper.saveCountyShape(shapeModel);
    }

    @Override
    public ShapeModel findByCoordinate(Coordinate coordinate) {
        String lon = coordinate.getLon();
        String lat = coordinate.getLat();
        String WKTPoint = "POINT("+lon+" "+ lat+")";
        List<ShapeModel> list = shpMapper.findByCoordinate(WKTPoint);
        if (list!=null && list.size()>0){
            ShapeModel model = list.get(0);
            //String data = model.getGeoStr();
            //String name = model.getName();
            //System.out.println("name = " + name);
            //System.out.println("data = " + data);
            //return name;
            return model;
        }
        //return "没有找到";
        return null;
    }

    @Override
    public int saveTownshipShape(TownshipShapeModel shapeModel) {
        return shpMapper.saveTownshipShape(shapeModel);

    }

    @Override
    public int saveCommonShape(CommonShapeModel shapeModel) {
        return shpMapper.saveCommonShape(shapeModel);

    }
}
